#!/usr/bin/env python

## Copyright (C) January 26, 2005 Erick P. Bodine
## email: erick_bodine@comcast.net
## webaddress

## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

# TODO: splashscreen if necessary
# TODO: all of the configuration file handling/parsing

"""
NAME
MyFocus.py

SYNOPSIS
MyFocus.py [options]

DESCRIPTION
This is my version of kfocus (http://sourceforge.net/kfocus) done in
wxPython with a few things of my own added in.  Since kfocus is in an
old version of Qt and has not been maintained in a long time, I decided
to do my own version.  The backend is an embedded database called
Metakit, that is accessed through a Python wrapper.

AUTHOR
Erick P Bodine
"""

import wx
import os
import sys
import logging
from optparse import OptionParser

import MyFocusFrame

__author__ = "$Author: ebodine $"
__date__ = "$Date: 2005-03-19 16:06:43 -0700 (Sat, 19 Mar 2005) $"
__version__ = "$Revision: 16 $"


# modules = {'mainframe': [0, '', 'mainframe.py']}

# NOTE: See Main.py in the wxPython/demo (~ line # 761), to use splashscreen

#class MySplashScreen(wxSplashScreen):
#    def __init__(self):
#        bmp = wxImage(opj("bitmaps/splash.gif")).ConvertToBitmap()
#        wxSplashScreen.__init__(self, bmp,
#                                wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
#                                4000, None, -1,
#                                style = wxSIMPLE_BORDER|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP)
#        EVT_CLOSE(self, self.OnClose)
#
#    def OnClose(self, event):
#        frame = wxPythonDemo(None, -1, "wxfocus")
#        frame.Show()
#        event.Skip()  # Make sure the default handler runs too...

class MyFocusApplication(wx.App):
    def OnInit(self):
        self.main = MyFocusFrame.create(None, opts.props)
        self.main.Show(True)
        self.SetTopWindow(self.main)

        return True

def main():
    """ The main function. """

    # NOTE: We will do some config file stuff here
    log.info("Starting MyFocus v. %s" % __version__)

    application = MyFocusApplication(0)
    application.MainLoop()

if __name__ == '__main__':
    
    # command line options
    usage = "%prog [options]"
    p = OptionParser(usage, version=os.path.basename(sys.argv[0])+__version__)
    
    p.add_option("-p", None, type="string", default="properties",
                dest="props", help="Path to an alternative properties file")
    p.add_option("", "--debug", action="store_const", const=1, default=0,
                dest="debug", help="Turn on debug logging")
    p.add_option("", "--man", action="store_const", const=1, default=0,
                dest="man", help="A more complete description of MyFocus")
    
    (opts, args) = p.parse_args()
    
    if opts.man == 1: print __doc__; sys.exit()
    
    # setup logging
    log = logging.getLogger("myfocus")
    handler = logging.StreamHandler()
    if opts.debug == 1:
        log.setLevel(logging.DEBUG)
        format = logging.Formatter("%(asctime)s %(levelname)-3s [%(module)s:%(lineno)d] %(message)s")
    else:
        log.setLevel(logging.INFO)
        format = logging.Formatter("%(asctime)s %(levelname)-3s %(message)s")
        
    handler.setFormatter(format)
    log.addHandler(handler)
    
    main()
